#ifndef VIEWER_H
#define VIEWER_H

#include <QtGui>

#include "glewinitialisation.h"
#include <QGLViewer/qglviewer.h>
using namespace qglviewer;

#if defined (__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include "keyframe.h"
#include "keyframeeditor.h"
#include "renderprocess.h"

class Viewer : public QGLViewer
{
  Q_OBJECT

 public :
  Viewer();
  ~Viewer();

  void setLogger(QTextEdit*);
  void setRenderProcess(RenderProcess*);
  void setKeyFrame(KeyFrame*);
  void setKeyFrameEditor(KeyFrameEditor*);

  QList<QString> volumeFilename();

  void loadVolume(QList<QString>);
  void loadLookupTable(QList<QImage>);
  
  QImage histogramImage1D();
  QImage histogramImage2D();

  void toggleBounds();
  void bounds(Vec&, Vec&);

  void setBoxSize(int);

  void set4DboxSize(Vec);
  Vec boxSize4D();

  int timeStep();

  void setImageSize(int, int);
  void setImageMode(int);
  void setImageFileName(QString);
  void setSaveSnapsots(bool);
  void dummydraw();

  float* getLUT();

  LightingInformation lightInfo();

 public slots :
  void glewInit();
  void captureKeyFrameImage(int);
  void setCurrentFrame(int);
  void updateLookFrom(Vec, Quaternion);
  void setLUT(float*);
  void endPlay();
  void setKeyFrame(int);
  void setBounds(Vec, Vec);
  void setSaveSnapshots(bool);
  void update4dInfo(Vec, int, float);
  void setLightInfo(LightingInformation);

 signals :
  void quitMahaDrishti();
  void nextFrame();
  void startRender();
  void replaceKeyFrameImage(int, QImage);
  void setKeyFrame(Vec, Quaternion,
		   int,
		   Vec, int,
		   QImage,
		   Vec, Vec,
		   float*);

 private slots :
  void resizeGL(int, int);
  void keyPressEvent(QKeyEvent*);
  void switchOffAutoBufferSwapping();


  void lightDirectionChanged(Vec);
  void applyLighting(bool);
  void applyEmissive(bool);
  void highlights(Highlights);
  void applyShadow(bool);
  void shadowBlur(float);
  void shadowScale(float);
  void shadowFOV(float);
  void shadowIntensity(float);

  void renderDone();

 protected :
  virtual void draw();
  virtual void fastDraw();
  virtual void init();

 private :
  RenderProcess *m_renderProcess;

  QTextEdit *m_log;
  
  KeyFrame *m_keyFrame;
  KeyFrameEditor *m_keyFrameEditor;

  uint m_windowWidth, m_windowHeight;

  int m_currFrame;
  int m_imageMode;
  bool m_saveSnapshots;
  QString m_imageFileName;

  QList<QString> m_volumeFilename;

  void commandEditor();
  void processCommand(QString);

  void saveImage();
  void saveMonoImage(QString, QChar, int);
  void saveSnapshot(QString);
};

#endif
